﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MonsterAnimations : MonoBehaviour
{
    private Animator _animator;
    private Monster _monster;
    private MonsterHealth _monsterhealth;
    private SpriteRenderer _spriteRenderer;

    private bool IsTurningY()
    {
        if (_monster.CurrentPointPosition.y - _monster.transform.position.y >= 0)
        {
            return true;
        }
        return false;
    }

    private void IsTurningX()
    {
        if (_monster.CurrentPointPosition.x - _monster.transform.position.x > 0)
        {
            _spriteRenderer.flipX=false;
        }
        else
        {
            _spriteRenderer.flipX=true;
        }
    }

    private bool IsDead()
    {
        if (_monsterhealth.CurrentHealth <= 0)
        {
            _monsterhealth.CurrentHealth = 0;
            return true;
        }
        return false;
    }


    // Start is called before the first frame update
    void Start()
    {
        _animator = GetComponent<Animator>();
        _monster = GetComponent<Monster>();
        _monsterhealth = GetComponent<MonsterHealth>();
        _spriteRenderer = GetComponent<SpriteRenderer>();
    }

    private void Update()
    {
        IsTurningX();
        PlayWalkAnimaion();
        PlayDieAnimaion();
    }

    private void PlayWalkAnimaion()
    {
        _animator.SetBool("IsTurning", IsTurningY());
    }

    private void PlayDieAnimaion()
    {
        _animator.SetBool("Die",IsDead());
    }
}
